<template>
	<om-addpage style="padding-top: 35px;" :menuName="menuName" @formSubmit="getFormValue" :busCode="busCode">
		<om-autoform ref="autoform" :initConfigData="mainConfigData" :initValue="initValue" @switchChange="switchChange"></om-autoform>
	</om-addpage>
</template>

<script>
	import { getUrl,confirmModal,errorModal, ignoreHtml,ptFloat, minusF } from '@/static/js/common.js';
	import {hasEditor,getEditorTitle, buildFormData,changeConfigAttr,formValidation, tranferToEditors, changeEditor,setSubmitSubValue, configSelectData, hasValue,formShowLoading ,getFormFields,formModelLoad,getWorkCacheKey,getEditor,insertAfterEditorArr} from '@/static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import moment from '@/static/js/moment.js'
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	
	export default{
		provide(){
			return{
				formPage:this
			}
		},
		data(){
			return buildFormData({
				userInfo:{},
				infoCacheKey:"hr-kq-askLeave-info-cache",
				replaceUserCacheKey:"hr-kq-askLeave-replaceUser-cache",
				code:"",
				endTime:"",
				endTime1:"",
				takeTimeType:"",
				startTimeType:"",
				endTimeType:"",
				continueDayType:"",
				leaveNaturalDayStrType:"",
				leaveWorkDayStrType:"",
				annualTimeType:"",
				entryType:'select',
				entryType1:'onEdit',
				fileKey:'41'
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId','orgId','platform'])
		},
		methods: {
			async getPosList(id){
				let _that = this
				let posList = await _that.getPosComboboxByUser(id)
				_that.$refs.autoform.changeEditor("replaceTile","replacePosId","type","selectbox")
				_that.$refs.autoform.changeEditor("replaceTile","replacePosId","data",configSelectData(posList,"id","posName"))
				_that.$refs.autoform.changeEditor("replaceTile","replacePosId","onSelect","onSelectReplacePos")
				_that.$refs.autoform.initSelectIndex("replaceTile","replacePosId")
			},
			onSelectReplacePos(item){
				let _that = this
				_that.$refs.autoform.formdata.replaceInstName = item.instName
			},
			getPosComboboxByUser(id){
				let _that = this
				return new Promise((resolve, reject) => {
					_that.om.request(
						"orgInstPosUserOfficial/getPosComboboxByUser",
						{
							userId:id
						
						}).then(res=>{
							resolve(res)			
					})
				})
			},
			verifyNew(){
				let _that = this
				_that.om.request(
					"taskLeave/verifyNew"
				).then(res=>{
					if(res.value){
						errorModal(_that,"提示信息",res.value,()=>{
							uni.navigateBack({
							})
						})
					}
				})
			},
			canContinueAskLeave(id){
				let _that = this
				_that.om.request(
					"taskLeave/canContinueAskleave",
					{
						infoId:id
					}
				).then(res=>{
					if(res.succeed && !res.value){
						_that.getUserInfo(id)
						_that.getInfo(id)
						_that.getListByCode()
						if(_that.$refs.autoform.formdata.startTime){
							_that.verifyFormDate(_that.$refs.autoform.formdata.startTime)
						}
					}else{
						errorModal(_that, "提示信息",res.value, function() {
							_that.$refs.autoform.clear("leavePersonTitle","infoId")
						});
					}
				})
			},
			switchChange(e){
				let _that = this
				if(e){
					_that.$refs.autoform.changeEditor("replaceTile","replaceStr",{
						showAdd:true
					})
					_that.$refs.autoform.formdata.replaceFlag = true
				}else{
					let arr = []
					_that.subEditorObj["replaceTile"].workList = arr
					_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"replaceStr",JSON.stringify(arr))
					_that.$set(_that.formdata,"replaceStr",JSON.stringify(arr))
					_that.$refs.autoform.changeEditor("replaceTile","replaceStr",{
						showAdd:false
					})
					_that.$refs.autoform.formdata.replaceFlag = false
				}
			},
			getWorkParam(){
				let _that = this
				return {
					userId:_that.$refs.autoform.formdata.infoId
				}
			},
			
			getListByCode(){
				let _that = this
				_that.om.request(
					"dictZero/getListByCode",
					{
						code:'36924',
						inCode:'36925'
					}
				).then(res=>{
					_that.$refs.autoform.changeEditor("leaveTimeTitle","replaceFlagStr",'data',configSelectData(res,'dicname','dicname'))
					_that.$refs.autoform.initSelectIndex("leaveTimeTitle","replaceFlagStr")
				})
			},
			getInfo(userId){
				let _that = this
				_that.om.request(
					"tworkInfo/getInfo",
					{
						userId:userId
					}
				).then(res=>{
					_that.subEditorObj["takeOffice"].workList = res.value
				})
			},
			getUserInfo(userId){
				let _that = this
				_that.om.request(
					"taskLeave/getUserInfo",
					{
						userId:userId
					}
				).then(res=>{
					if(res.value){
						var obj = res.value.temployeeResponse;
						for (var key in obj) {
						    if (obj.hasOwnProperty(key)) {
								_that.$refs.autoform.formdata[key] = obj[key]
						    }
						}
						
						// _that.$refs.autoform.formdata.salaryPosId =  res.value.temployeeResponse.salaryPosId
						// _that.$refs.autoform.formdata.salaryPosName =  res.value.temployeeResponse.salaryPosName	
						_that.$refs.autoform.formdata.salaryInstId =  res.value.temployeeResponse.salaryPosInstId	
						_that.$refs.autoform.formdata.salaryInstName = res.value.temployeeResponse.salaryPosInstName	
						// _that.$refs.autoform.formdata.attributeId=  res.value.temployeeResponse.attributeId
						// _that.$refs.autoform.formdata.attributeName =  res.value.temployeeResponse.attributeName
						
						// _that.$refs.autoform.formdata.birthdate =  res.value.temployeeResponse.birthdate	
						// _that.$refs.autoform.formdata.birthPlace =  res.value.temployeeResponse.birthPlace	
						// _that.$refs.autoform.formdata.sexName =  res.value.temployeeResponse.sexName	
						// _that.$refs.autoform.formdata.highestEduName = res.value.temployeeResponse.highestEduName	
						// _that.$refs.autoform.formdata.mobile=  res.value.temployeeResponse.mobile
						// _that.$refs.autoform.formdata.entrydate =  res.value.temployeeResponse.entrydate
						_that.$refs.autoform.formdata.takeTime = res.value.taskLeave.takeTime
						if((res.value.taskLeave.annualTime + '').indexOf('天') != -1){ 
							_that.$refs.autoform.formdata.annualTime = res.value.taskLeave.annualTime
						}else{
							_that.$refs.autoform.formdata.annualTime = res.value.taskLeave.annualTime + '天'
						}
						
						
						_that.om.request(
							"tinstitution/getInstInfo",
							{
								instId:res.value.temployeeResponse.salaryPosInstId
							}
						).then(res=>{
							_that.$refs.autoform.formdata.instLevelId =  res.value.instcatId
							_that.$refs.autoform.formdata.instLevelName =  res.value.instcatName
						})
					}
				})
			},
			showBtn(options) {
				let _that = this
				_that.$refs.autoform.changeConfigAttr("leaveTimeTitle", "showButton", true)
				_that.$refs.autoform.changeConfigAttr("leaveTimeTitle", "buttonText", "按天请假")
				_that.$refs.autoform.changeConfigAttr("leaveTimeTitle", "buttonLink",
					"/pages/form/hr-kq-askleave/askleaveTemplate?busCode="+options.code)
			},
			initLoad(options){
				let _that = this;
				_that.code = options.code
				var ajaxArr = [{
						url:"askLeaveDict/getList"
					},
					{
						url:"taskLeave/getTitleInfo"
					},
					{
						url: "wxPosBusiAuth/isnewList",
						param: {
							code: _that.code
						},
						method: "post"
					},
					{
						url:"wxPosBusiAuth/defaultTableMaker",
						param: {
							code: _that.code
						},
						method: "post"
					}];
				var fileId = options.fileId
					if(fileId){
						ajaxArr.push({
							url:"taskLeave/getInfo",
							param:{
								id:fileId,
								orgId:this.orgId
							}
						})
					}
				formModelLoad(ajaxArr, function(res, mainData) {
					var defaultPosId = res[3].value.id || '';
					var defaultPosName = res[3].value.posName || '';
					var defaultInstId = res[3].value.instId || '';
					var defaultInstName = res[3].value.instName || '';
					changeEditor('topinfo', 'zposId', 'data', configSelectData(res[2], 'id', 'posName'), mainData)
					_that.takeTimeType = getEditor("leaveTimeTitle",'takeTime',mainData).type
					_that.startTimeType = getEditor("leaveTimeTitle",'startTime',mainData).type
					_that.endTimeType = getEditor("leaveTimeTitle",'endTime',mainData).type
					_that.continueDayType = getEditor("leaveTimeTitle",'continueDay',mainData).type
					_that.leaveNaturalDayStrType = getEditor("leaveTimeTitle",'leaveNaturalDayStr',mainData).type
					_that.leaveWorkDayStrType = getEditor("leaveTimeTitle",'leaveWorkDayStr',mainData).type
					_that.annualTimeType = getEditor("leaveTimeTitle",'annualTime',mainData).type
					let editorArr = [{
							checkedit: null,
							editReadonly: null,
							isfull: null,
							digit:true,
							max: "",
							min: "",
							prompt: "请输入0.5的倍数",
							nameField: "leaveDay",
							required: false,
							title: "请假天数",
							type: "",
							valueField: "leaveDay",
							onSelect:'onInputDay'
						},
						{
							editReadonly: null,
							isfull: null,
							data:[],
							max: "",
							initIndex:0,
							min: "",
							nameField: "yStartDate",
							onSelect: "",
							prompt: "请选择",
							required: false,
							title: "开始时间",
							type: "",
							valueField: "yStartDate",
							onSelect:'onSelectYstart'
						}]
						insertAfterEditorArr("leaveTimeTitle", 'salaryRatio',editorArr,mainData)
					changeEditor('topinfo','zuserId',{
						defaultName:_that.userName,
						defaultValue:_that.userId
					},null, mainData);
					//获取下拉框内容数据 修改对应内容
					changeEditor("leavePersonTitle","infoId",{
						link:'../../public/pageSearch/pageSearch',
						"linkParam":{
							other:JSON.stringify({}),
							url:urlUtil.findUserAsSameInst().url,
							namefield:urlUtil.findUserAsSameInst().namefield,
							extrafield:urlUtil.findUserAsSameInst().extrafield,
							initload:true,
							searchfield:"q",
							cachename:_that.infoCacheKey,
							placeholder:"请输入姓名"
						}
					},null,mainData)
					changeEditor('leaveTimeTitle','leaveClassId','data',configSelectData(res[0],'id','dicname'),mainData);
					let tempFileList = []
					let fileUrlList = []
					changeEditor('bottominfo','bottomFileUpload','fileUploadKey',"41",mainData)
					changeEditor("bottominfo","bottomFileUpload","tempFileList", tempFileList,mainData)
					changeEditor("bottominfo","bottomFileUpload","fileUrlList", fileUrlList,mainData)
					changeEditor('replaceTile', "replaceUserId", {
						'link': '../../public/searchUser/searchUser',
						"linkParam": {
							namefield: urlUtil.userPageUrl().namefield,
							searchfield: "q",
							cachename: _that.replaceUserCacheKey,
							isUserPos:true,
							isSingle:true,
							placeholder: urlUtil.userPageUrl().prompt,
							pagination: true
						}
					}, null,mainData)
					if(_that.subEditorObj["takeOffice"]){
						let att = {
							showAdd:false,
							showArrow:false,
							showDel:false
						}
						let configData = _that.subConfigData["takeOffice"]
						if(hasEditor("takeOffice","posName",configData)){
							let title = getEditorTitle("takeOffice","posName",configData)
							att.titleTemplate = title+":<%= posName %>"
						}
						if(hasEditor("takeOffice","salaryPosFlagStr",configData)){
							let title = getEditorTitle("takeOffice","salaryPosFlagStr",configData)
							att.titleTemplate = att.titleTemplate+"<%= salaryPosFlagStr %>"
						}
						if(hasEditor("takeOffice","parentUserName",configData)){
							let title = getEditorTitle("takeOffice","parentUserName",configData)
							att.subtitle1Template = title+":<%= parentUserName %>"
						}
						if(hasEditor("takeOffice","instShort",configData)){
							let title = getEditorTitle("takeOffice","instShort",configData)
							att.subtitle1Template = att.subtitle1Template +'|'+  title +":<%= instShort %>"
						}
						if(hasEditor("takeOffice","parentInst",configData)){
							let title = getEditorTitle("takeOffice","parentInst",configData)
							att.subtitle2Template = title +":<%= parentInst %>"
						}
						if(hasEditor("takeOffice","salaryWay",configData)){
							let title = getEditorTitle("takeOffice","salaryWay",configData)
							att.subtitle2Template = att.subtitle2Template?att.subtitle2Template +'|'+ title +":<%= salaryWay %>":title +":<%= salaryWay %>"
						} 
						changeEditor("takeOffice","workStr",att,mainData)
					}
					
						if(_that.subEditorObj["replaceTile"]){
							let att = {
								getWorkParam:"getWorkParam",
								showAdd:false
							}
							let configData = _that.subConfigData["replaceTile"]
							if(hasEditor("replaceTile",'posId',configData)){
								let title = getEditorTitle("replaceTile",'posId',configData)
								att.titleTemplate = title+':<%= posName || "未填写"%>'
							}
							changeEditor("replaceTile","replaceStr",att,mainData)
						}
						if(hasEditor("title_leaveStatistics","leaveStatistics",mainData)){ 
							changeEditor("title_leaveStatistics","leaveStatistics",'prompt',"",mainData)
						}
						changeEditor("leaveTimeTitle","startTime","noInitDate",'true',mainData)
						changeEditor("leaveTimeTitle","endTime","noInitDate",'true',mainData)
						_that.$set(_that.formdata,"titleInfo",res[1].value)
						changeConfigAttr("leaveTimeTitle","subTitle",res[1].value,mainData)
					if(fileId){
						var fieldArr = getFormFields(mainData)
						fieldArr.push("id",'leaveDate')
						for(var i in res[4].value.temployeeResponse){
							if(fieldArr.includes(i)){
								_that.$refs.autoform.$set(_that.$refs.autoform.formdata,i,res[4].value.temployeeResponse[i])
								_that.$set(_that.formdata,i,res[4].value.temployeeResponse[i])
							}
						}
						for(var i in res[4].value.taskLeave){
							if(fieldArr.includes(i)){
								if(i== 'startTime'){
									if(res[4].value.taskLeave.leaveClassId == 7){
										_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'yStartDate',res[4].value.taskLeave[i])
										_that.$set(_that.formdata,'yStartDate',res[4].value.taskLeave[i])
									}
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'startTime',res[4].value.taskLeave[i])
									_that.$set(_that.formdata,'startTime',res[4].value.taskLeave[i])
								}else if(i== 'leaveDate'){
									_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'leaveDay',res[4].value.taskLeave[i])
									_that.$set(_that.formdata,'leaveDay',res[4].value.taskLeave[i])
								}else if(i == 'annualTime'){
									if((res[4].value.taskLeave[i]+'').indexOf('天') != -1){
										_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'annualTime',res[4].value.taskLeave[i])
										_that.$set(_that.formdata,'annualTime',res[4].value.taskLeave[i])
									}else{
										_that.$refs.autoform.$set(_that.$refs.autoform.formdata,'annualTime',res[4].value.taskLeave[i] + '天')
										_that.$set(_that.formdata,'annualTime',res[4].value.taskLeave[i] + '天')
									}
								}else{
									if(i != 'leaveDay'){
										_that.$refs.autoform.$set(_that.$refs.autoform.formdata,i,res[4].value.taskLeave[i])
										_that.$set(_that.formdata,i,res[4].value.taskLeave[i])
									}
								}
							}
						}
						if(_that.$refs.autoform.formdata.replaceUserId){
							_that.getPosList(_that.$refs.autoform.formdata.replaceUserId)
						}
						if(_that.formdata.bottomFileList){
							let tempFileList = []
							let fileUrlList = _that.formdata.bottomFileList.map(t=>{
								tempFileList.push(t.fileSaveName)
								return t.fileSaveName
							})
							changeEditor("bottominfo","bottomFileUpload","tempFileList", tempFileList,mainData)
							changeEditor("bottominfo","bottomFileUpload","fileUrlList", fileUrlList,mainData)
						}
						if(_that.$refs.autoform.formdata.leaveClassId == 7){
							_that.getStartNodeList1(_that.$refs.autoform.formdata.infoId,_that.$refs.autoform.formdata.startTime)
						}
						if(_that.subEditorObj["takeOffice"]){
							let workList = _that._.cloneDeep(res[4].value.taskLeave_workinfos)
							_that.subEditorObj["takeOffice"].workList = workList
							_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"workStr",JSON.stringify(workList))
							_that.$set(_that.formdata,"workStr",JSON.stringify(workList))
						}
						if(_that.subEditorObj["replaceTile"]){
							let replaceList = _that._.cloneDeep(res[4].value.taskLeave_data)
							_that.subEditorObj["replaceTile"].workList = replaceList
							_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"replaceStr",JSON.stringify(replaceList))
							_that.$set(_that.formdata,"replaceStr",JSON.stringify(replaceList))
						}
						_that.$nextTick(function(){
							if(_that.$refs.autoform){
								_that.$refs.autoform.initSelectIndex('leaveTimeTitle','leaveClassId')
								_that.getListByCode()
								if(_that.$refs.autoform.formdata.replaceFlagStr){
									_that.switchChange(_that.$refs.autoform.formdata.replaceFlagStr)
								}
							}
							_that.insertEditor(_that.$refs.autoform.formdata.leaveClassId,_that.entryType1s)
						})
					}else{
						_that.verifyNew()
					}
					_that.$nextTick(function(){
						if(!_that.$refs.autoform.formdata.infoId){
							_that.$refs.autoform.formdata.infoId = _that.userId
							_that.$refs.autoform.formdata.infoName = _that.userName
							_that.canContinueAskLeave(_that.userId)
						}
						
						// if(!_that.$refs.autoform.formdata.zposId){
						// 	_that.$refs.autoform.initSelectVal("topinfo","zposId")
						// }else{
						// 	_that.$refs.autoform.initSelectIndex('topinfo',"zposId")
						// }
						
						if(!_that.$refs.autoform.formdata.zposId){
							_that.$refs.autoform.formdata.zposId = defaultPosId
							_that.$refs.autoform.formdata.zposName = defaultPosName
							_that.$refs.autoform.formdata.zinstId = defaultInstId
							_that.$refs.autoform.formdata.zinstName = defaultInstName
							_that.$nextTick(function() {
								_that.$refs.autoform.initSelectIndex('topinfo',"zposId")
							})
						}else{
							_that.$refs.autoform.initSelectIndex('topinfo',"zposId")
						}
						
						_that.showBtn(options)
					})
				},options)
			},
			// isWorkDay(str,time){
			// 	var _that = this
			// 	var obj = {
			// 		time:time,
			// 		userId:this.userId
			// 	}
			// 	_that.om.request(
			// 	"taskLeave/isWeekend",
			// 	obj,
			// 	"post"
			// 	).then(res =>{
			// 		if(res.succeed){
			// 		}else{
			// 			confirmModal(_that,'提示信息',res.msg,function(){},function(){
			// 				if(str === 'startTime'){
			// 					_that.$refs.autoform.clear("leaveTimeTitle","startTime")
			// 				}else{
			// 					_that.$refs.autoform.clear("leaveTimeTitle","endTime")
			// 					_that.$refs.autoform.clear("leaveTimeTitle","day")
			// 				}
			// 			})
			// 		}
			// 	}
			// )
				
			// 	// if(num == 0 || num == 6){
			// 	// 	confirmModal(this,'提示信息','当前选择的时间为休息日是否继续？',function(){},function(){
			// 	// 		_that.$refs.autoform.clear("leaveTimeTitle","startTime")
			// 	// 	})
			// 	// }
			// },
			getStartNodeList1(id,time){
				let _that = this
				_that.om.request(
					"ttimeTable/getStartNodeList",
					{
						userId: id
					}
				).then(res=>{
					let hours = time.split(" ")[1]
					for(let item of res){
						if(item.startTime == hours){
							_that.endTime = item.endTime
							_that.endTime1 = item.endTime1
						}
					}
				})
			},
			getStartNodeList(){
				let _that = this
				_that.om.request(
					"ttimeTable/getStartNodeList",
					{
						userId: _that.$refs.autoform.formdata.infoId
					}
				).then(res=>{
					_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","data",configSelectData(res,"name","name",true))
					_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","showDetail1","name")
					_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","showDetail2","startTime")
				})
			},
			verifyFormDate(item){
				let _that = this 
				_that.om.request(
					"hrPosUtil/verifyFormDate",
					{
						date: item,
						busCode: _that.code
					}
				).then(res=>{
					if(res.value){
						errorModal(_that,"提示信息",ignoreHtml(res.value),()=>{
							_that.$refs.autoform.clear("leaveTimeTitle","startTime")
							_that.$refs.autoform.clear("title_leaveStatistics","leaveStatistics")
							}
						)
					}else{
						_that.getLeaveStatisticsInfo(item)
					}
				})
			},
			onInputDay(val){
				let _that = this
				let day = Number(val)
				if(day<0.5){
					_that.$refs.autoform.formdata.leaveDay = 0.5
				}else{
					let num = day%0.5
					if(num != 0){
						_that.$refs.autoform.formdata.leaveDay = day-num
					}
				}
				_that.verifyYearLeave()
			},
			onStartTime(item){
				let _that = this
				let time = this.$refs.autoform.formdata.startTime
				// this.isWorkDay('startTime',time)
				_that.$refs.autoform.clear("leaveTimeTitle","endTime")
				if(!_that.$refs.autoform.formdata.infoId){
					let title = _that.$refs.autoform.getEditorTitle("leavePersonTitle","infoId")
					_that.om.toast("请先选择"+title)
					_that.$refs.autoform.clear("leaveTimeTitle","startTime")
					return
				}
				_that.verifyFormDate(item)
			},
			onEndTime(value){
				let _that = this
				let time = _that.$refs.autoform.formdata.endTime
				let title = _that.$refs.autoform.getEditorTitle("leaveTimeTitle","startTime")
				let title1 = _that.$refs.autoform.getEditorTitle("leaveTimeTitle","endTime")
				if(!_that.$refs.autoform.formdata.startTime){
					errorModal(_that,'提示信息',"请先选择"+title,()=>{
						_that.$refs.autoform.clear("leaveTimeTitle","endTime")
					})
				}
				let result =  moment(value).isBefore(_that.$refs.autoform.formdata.startTime) 
				if(result){
					errorModal(_that,'提示信息',title1+'要大于'+ title +'，请重新选择！',()=>{
						_that.$refs.autoform.clear("leaveTimeTitle","endTime")
					})
				}
				// _that.isWorkDay('endTime',time)
			},
			getLeaveStatisticsInfo(item){
				let _that = this
				_that.om.request(
					"taskLeave/getLeaveStatisticsInfo",{
						startTime:item,
						userId: _that.$refs.autoform.formdata.infoId
					}
				).then(res=>{
					_that.$refs.autoform.formdata.leaveStatistics = res.value
				})
			},
			calEndTime(){
				let _that = this
				_that.om.request(
					"ttimeTable/calEndTime",
					{
						startTime: _that.$refs.autoform.formdata.startTime,
						date: _that.$refs.autoform.formdata.leaveDay,
						endTime: _that.endTime,
						endTime1: _that.endTime1
					}
				).then(res=>{
					if(res.succeed){
						_that.$refs.autoform.formdata.endTime = res.value
					}else{
						_that.om.toast(res.msg)
					}
					_that.getLeaveStatisticsInfo(_that.$refs.autoform.formdata.startTime)
				})
			},
			verifyYearLeave(){
				let _that = this
				if(!_that.$refs.autoform.formdata.yStartDate){
					return
				}
				_that.om.request(
					"taskLeave/verifyYearLeave",
					{
						leaveClassId: _that.$refs.autoform.formdata.leaveClassId,
						userId: _that.$refs.autoform.formdata.infoId,
						startTime: _that.$refs.autoform.formdata.startTime
					}
				).then(res=>{
					if(res.succeed){
						if(res.value){
							_that.om.toast(res.value)
							_that.$refs.autoform.clear("leaveTimeTitle","yStartTime")
							_that.$refs.autoform.clear("leaveTimeTitle","yStartDate")
							_that.$refs.autoform.clear("leaveTimeTitle","endTime")
						}else{
							_that.calEndTime()
						}
					}
				})
			},
			onSelectYstart(item,date){
				let _that = this
				_that.$refs.autoform.$set(_that.$refs.autoform.formdata,"startTime", date+' ' + item.attr.startTime)
				_that.$refs.autoform.formdata.yStartDate = date+' ' + item.attr.startTime
				if(!item.attr.startTime){
					_that.$refs.autoform.clear("leaveTimeTitle","yStartDate")
					return
				}
				_that.endTime = item.attr.endTime
				_that.endTime1 = item.attr.endTime1
				_that.verifyYearLeave()
			},
			insertEditor(id,entryType){
				let _that = this
				if(id == 7){
				let editorArr = []
					if(!_that.$refs.autoform.formdata.yStartDate){
						_that.$refs.autoform.changeEditor("leaveTimeTitle","leaveDay","required",true)
						_that.$refs.autoform.changeEditor("leaveTimeTitle","leaveDay","type","numberbox")
						_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","type","opickerbox")
						_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","required",true)
						_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","onSelect","onSelectYstart")
							if(entryType ==_that.entryType){
								_that.$refs.autoform.clear("leaveTimeTitle",'yStartDate','type')
								_that.$refs.autoform.clear("leaveTimeTitle",'leaveDay','type')
							}
							_that.getStartNodeList()
					}else{
						_that.$refs.autoform.changeEditor("leaveTimeTitle","leaveDay","required",true)
						_that.$refs.autoform.changeEditor("leaveTimeTitle",'yStartDate','type','opickerbox')
						_that.$refs.autoform.changeEditor("leaveTimeTitle",'leaveDay','type','numberbox')
						_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","required",true)
					}
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'takeTime','type','')
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'annualTime','type',_that.annualTimeType)
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'startTime','type','')
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'endTime','type','labelbox')
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'continueDay','type','')
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'leaveNaturalDayStr','type','')
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'leaveWorkDayStr','type','')
					if(_that.$refs.autoform.formdata.leaveDay && _that.$refs.autoform.formdata.yStartDate){
						if(_that.endTime && _that.endTime1){
							_that.verifyYearLeave()
						}
					}
				}else{
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'yStartDate',"type","")
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'leaveDay',"type","")
					_that.$refs.autoform.changeEditor("leaveTimeTitle","yStartDate","required",false)
					_that.$refs.autoform.changeEditor("leaveTimeTitle","leaveDay","required",false)
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'annualTime','type','')
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'takeTime','type',_that.takeTimeType)
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'startTime','type',_that.startTimeType)
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'endTime','type',_that.endTimeType)
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'continueDay','type',_that.continueDayType)
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'leaveNaturalDayStr','type',_that.leaveNaturalDayStrType)
					_that.$refs.autoform.changeEditor("leaveTimeTitle",'leaveWorkDayStr','type',_that.leaveWorkDayStrType)
				}
			},
			//下拉框选择后执行方法
			onSelectLeaveType(item){
				let _that = this
				_that.$refs.autoform.formdata.salaryRatio = item.ratio
				if(item.defaultId == 10){
					_that.om.request(
						"timeBreakShow/getHourDesc",
						{
							userId: _that.$refs.autoform.formdata.infoId,
						}
					).then(data=>{
						var flag = "";
						if (data.succeed && data.value) {
							flag = parseFloat(data.value);
						}
						
						if(!flag){
							let title = _that.$refs.autoform.getEditorTitle("leaveTimeTitle",'leaveClassId')
							let name = _that.$refs.autoform.formdata.infoName
							errorModal(_that, "提示信息",'当前请假人'+name+'没有可调休工时，“'+title+'”不能选择调休假！', function() {
								_that.$refs.autoform.clear("leaveTimeTitle",'leaveClassId')
								_that.$refs.autoform.clear("leaveTimeTitle","salaryRatio")
							});
						}
						
					})
				}
				_that.insertEditor(item.id,_that.entryType)
			},
			//表单提交
			getFormValue(){
				let _that = this 
				var checkRes = formValidation(this.$refs.autoform.configData,this.formdata)
				if(checkRes){
					this.om.toast(checkRes)
				}else{
					_that.save()
				}
			},
			save(){
				let _that = this
				_that.formdata.updateBottomFileFlag= true
				if(Object.prototype.toString.call(_that.$refs.autoform.formdata.bottomFileList) == "[object String]"){
					_that.formdata.bottomFileListStr = _that.$refs.autoform.formdata.bottomFileList|| ''
				}else{
					_that.formdata.bottomFileListStr = JSON.stringify(_that.$refs.autoform.formdata.bottomFileList || []) || ''
					
				}
				delete _that.formdata.bottomFileUpload
				delete _that.formdata.bottomFileList
				if(_that.formdata.replaceFlag && (_that.subEditorObj["replaceTile"].length<1)){
					_that.om.toast("安排人员替岗后需要填写临时替岗人，请继续编辑。")
					return 
				}
				if(_that.formdata.leaveClassId == 7 && _that.formdata.yStartDate){
					_that.formdata.startTime = _that.formdata.yStartDate
				}
				if(_that.formdata.startTime){
					_that.formdata.startDate = _that.formdata.startTime.split(" ")[0]
					_that.formdata.startNodeTime = _that.formdata.startTime.split(" ")[1]
				}
				if(_that.formdata.leaveDay && _that.formdata.leaveClassId == 7){
					_that.formdata.leaveDate = _that.formdata.leaveDay
				}
				if(this.checkedit){
					this.om.formSave('taskLeave/saveEdit',_that.formdata,_that)					
				}else{
					this.om.formSave('taskLeave/save',_that.formdata,_that)					
				}
			}
		},
		onUnload(){
					//#ifdef APP-PLUS
					let _that = this;
					if (_that.$refs.autoform) {
						for (var fieldId in _that.subEditorObj) {
							uni.removeStorage({
								key: getWorkCacheKey(fieldId)
							});
						}
					}
					//#endif
				},
		onLoad(options){
			this.initLoad(options);
			uni.removeStorageSync('askLeaveTemplate');
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				for(let fileId in _that.subEditorObj){
					let editor = _that.subEditorObj[fileId]
					uni.getStorage({
						key:getWorkCacheKey(fileId),
						success:(res)=>{
							if(res.data){
								editor.workList = res.data
								uni.removeStorage({
									key:getWorkCacheKey(fileId)
								})
							}
						}
					})
				}
				uni.getStorage({
					key:_that.infoCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.infoId = d.id
							formdata.infoName = d.username
							_that.$refs.autoform.clear("leaveTimeTitle","leaveClassId")
							_that.$refs.autoform.clear("leaveTimeTitle","salaryRatio")
							_that.$refs.autoform.clear("leaveTimeTitle","replaceFlagStr")
							_that.$refs.autoform.clear("leaveTimeTitle","startTime")
							_that.$refs.autoform.clear("leaveTimeTitle","endTime")
							_that.$refs.autoform.clear("leavePersonTitle","salaryPosId")
							_that.$refs.autoform.clear("leavePersonTitle","salaryInstId")
							_that.$refs.autoform.clear("leavePersonTitle","instLevelId")
							_that.$refs.autoform.clear("leavePersonTitle","attributeId")
							_that.canContinueAskLeave(d.id)
							uni.removeStorage({
								key:_that.infoCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key:_that.replaceUserCacheKey,
					success:(res)=>{
						if(res){
							let formdata = _that.$refs.autoform.formdata
							let d = res.data[0]
							formdata.replaceUserId = d.id
							formdata.replaceUserName = d.username
							formdata.replacePosId = d.posId
							formdata.replacePosName = d.posName
							formdata.replaceInstName = d.instName
							_that.getPosList(d.id)
							uni.removeStorage({
								key:_that.replaceUserCacheKey
							})
						}
					}
				})
				uni.getStorage({
					key: "askLeaveTemplate",
					success: (res) => {
						if (res.data) {
							let formdata = _that.$refs.autoform.formdata
							let d = JSON.parse(res.data);
							d.id = d.leaveTypeId
							formdata.leaveClassId = d.leaveTypeId
							formdata.leaveClassName = d.leaveTypeName
							_that.onSelectLeaveType(d)
							formdata.startTime = d.startDate + ' ' + d.startNodeTimeId
							formdata.leaveDay = d.leaveDate
							_that.endTime = d.ed
							_that.endTime1 = d.ed1
							_that.calEndTime()
							_that.$nextTick(function() {
								_that.$refs.autoform.initSelectIndex('leaveTimeTitle',"leaveClassId")
							})

							// uni.removeStorage({
							// 	key: "askLeaveTemplate"
							// })
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>